import scrapy


class AiqiyiSpider(scrapy.Spider):
    name = "aiqiyi"
    # allowed_domains = ["baidu.com"]
    # start_urls = [f"https://mesh.if.iqiyi.com/portal/lw/videolib/data?uid=&passport_id=&ret_num=60&pcv=13.111.23635&version=13.111.23635&device_id=62d5a57b7069a7eb7ca6828c483855f4&channel_id=1&page_id={i}&session=e07d9822f7d4a8f2a75c9702f9e68ec8&os=&conduit_id=&vip=0&auth=&recent_selected_tag=&ad=%5B%7B%22lm%22%3A5%2C%22position%22%3A%22library%22%7D%5D&adExt=%7B%22r%22%3A%222.6.4-ares6-pure%22%7D&dfp=a1a4ed9b9d3e1246678c2e97844691a0180f6bc46643c521b955eb340ab08662b5&filter=%7B%22mode%22%3A%2224%22%7D" for i in range(1,10)]


    async def start(self):
        urls=[f"https://mesh.if.iqiyi.com/portal/lw/videolib/data?uid=&passport_id=&ret_num=60&pcv=13.111.23635&version=13.111.23635&device_id=62d5a57b7069a7eb7ca6828c483855f4&channel_id=1&page_id={i}&session=e07d9822f7d4a8f2a75c9702f9e68ec8&os=&conduit_id=&vip=0&auth=&recent_selected_tag=&ad=%5B%7B%22lm%22%3A5%2C%22position%22%3A%22library%22%7D%5D&adExt=%7B%22r%22%3A%222.6.4-ares6-pure%22%7D&dfp=a1a4ed9b9d3e1246678c2e97844691a0180f6bc46643c521b955eb340ab08662b5&filter=%7B%22mode%22%3A%2224%22%7D" for i in range(1,10)]
        for url in urls:
            yield scrapy.Request(url=url)

    def parse(self, response):
        self.logger.debug(f"正在爬取{response.url}")
        items = response.json()["data"]
        for item in items:
            title = item['display_name']
            print(title)
